# Refer to the document for workspace information: https://help.aliyun.com/document_detail/2746874.html

from http import HTTPStatus
import dashscope

from settings import (
  BAILIAN_API_KEY
)


dashscope.api_key = BAILIAN_API_KEY

def run_bailian_model(system_prompt, full_prompt, model_name):
  message = [
    {
      "role": "system",
      "content": system_prompt,
    },
    {
      "role": "user",
      "content": full_prompt,
    },
  ]
  # 多轮对话
  response = dashscope.Generation.call(
    model=model_name,
    messages=message,
    temperature=0.2, # 温度越低越稳定，温度越高越有自主意识
    result_format='message',  # set the result to be "message"  format.
    stream=False, # 是否以流式输出
  )
  if response.status_code != HTTPStatus.OK:
    print(response)

  return response['output']['choices'][0]['message']['content']